<template>
  <div class="app-container">
    <div class="item2">
      <div class="header">
        <div class="title1">
          <i class="el-icon-data-analysis"></i><span>立库托盘查询</span>
        </div>
        <!-- <el-date-picker
          v-model="Querydate"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker> -->
        <!-- <el-input v-model="barcode" placeholder="请输入内容"></el-input>
        <el-button type="primary" @click="handleClick" class="passbutton">查询</el-button> -->
        <div class="backB">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
        </div>
      </div>
      <div class="tabsList">
        <el-tabs v-model="activeName" @tab-click="handleClick" class="tabsItem">
          <el-tab-pane label="滑道口查询" name="barCodename"
            ><div class="scanner">
              <div class="barcodetext">任务编号：</div>
              <el-input
                v-model="barCode"
                ref="barcodeInput"
                placeholder="请输入任务编号"
                @change="bChandleQuery"
              />
              <el-button
                type="primary"
                class="btn"
                icon="el-icon-search"
                size="medium"
                @click="bChandleQuery"
                >搜索</el-button
              >
            </div>
            <el-table
              :data="bCtableData"
              border
              height="680"
              v-loading="bCloading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
            >
              <el-table-column align="center" prop="taskNo" label="任务编号">
              </el-table-column>
              <el-table-column align="center" prop="scantime" label="扫码时间">
              </el-table-column>
              <el-table-column align="center" prop="resourceNode" label="BCR名称">
              </el-table-column>
              <el-table-column
                align="center"
                prop="status"
                label="道口"
              >
              </el-table-column> </el-table
          ></el-tab-pane>
          <el-tab-pane label="托盘待执行任务查询" name="pendingTask"
            ><div class="formCenter">
              <el-form
                :model="pTqueryParams"
                size="large"
                :inline="true"
                ref="pTqueryForm"
                :rules="pTformRules"
                label-width="95px"
              >
                <el-form-item label="单据编号:" prop="billNo">
                  <el-input
                    v-model="pTqueryParams.billNo"
                    placeholder="请输入单据编号"
                    clearable
                    @keyup.enter.native="pThandleQuery"
                  />
                </el-form-item>
                <el-form-item label="WMS任务号:" prop="upperSystemTaskId">
                  <el-input
                    v-model="pTqueryParams.upperSystemTaskId"
                    placeholder="请输入WMS任务号"
                    clearable
                    @keyup.enter.native="pThandleQuery"
                  />
                </el-form-item>
                <el-form-item label="任务类型" prop="status">
                  <el-select
                    v-model="pTqueryParams.status"
                    placeholder="请选择任务类型"
                    clearable
                  >
                    <el-option
                      v-for="dict in dict.type.status_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="订单类型" prop="billType">
                  <el-select
                    v-model="pTqueryParams.billType"
                    placeholder="请选择订单类型"
                    clearable
                  >
                    <el-option
                      v-for="dict in dict.type.bill_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="托盘编码:" prop="containerNo">
                  <el-input
                    v-model="pTqueryParams.containerNo"
                    placeholder="请输入托盘编码"
                    clearable
                    @keyup.enter.native="pThandleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="medium"
                    @click="pThandleQuery"
                    >搜索</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
            <el-table
              :data="pTtableData"
              border
              height="680"
              v-loading="pTloading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
            >
              <!-- <el-table-column align="center" prop="sourceArea" label="巷道">
              </el-table-column> -->
              <el-table-column align="center" prop="containerNo" label="托盘码">
              </el-table-column>
              <el-table-column align="center" prop="status" label="任务类型">
                <!-- <template slot-scope="scope">
                  <dict-tag
                    :options="dict.type.status_type"
                    :value="scope.row.status"
                  />
                </template> -->
              </el-table-column>
              <el-table-column
                align="center"
                prop="upperSystemTaskId"
                label="WMS任务号"
              >
              </el-table-column>
              <el-table-column align="center" prop="billNo" label="单据编号">
              </el-table-column>
              <el-table-column
                align="center"
                prop="udf02"
                label="是否机械手拣选"
              >
              </el-table-column>
              <el-table-column align="center" prop="repose" label="是否整托">
              </el-table-column>
              <el-table-column align="center" prop="workType" label="工作类型">
              </el-table-column>
              <el-table-column align="center" prop="billType" label="订单类型">
                <!-- <template slot-scope="scope">
                  <dict-tag
                    :options="dict.type.bill_type"
                    :value="scope.row.billType"
                  />
                </template> -->
              </el-table-column>
              <!-- <el-table-column align="center" prop="status" label="状态">
              </el-table-column> -->
              <el-table-column align="center" prop="extend1" label="品名">
              </el-table-column>
              <el-table-column align="center" prop="itemId" label="产品代码">
              </el-table-column>
              <el-table-column align="center" prop="planQty" label="任务数量">
              </el-table-column>
              <el-table-column
                align="center"
                prop="createTime"
                label="创建时间"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="priorty"
                label="优先级"
                width="230"
              >
                <template slot-scope="scope">
                  <!-- <el-select v-model="scope.row.priorty" placeholder="请选择">
                    <el-option
                      v-for="item in priortyOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
                  <el-input
                    v-model="scope.row.priorty"
                    placeholder="请输入优先级"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                align="center"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="handleUpdate(scope.row)"
                    >修改优先级</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
            <div>
              <pagination
                v-show="pTtotal > 0"
                :total="pTtotal"
                :page.sync="pTqueryParams.pageNum"
                :limit.sync="pTqueryParams.pageSize"
                @pagination="pThandleQuery"
              />
            </div>
          </el-tab-pane>
          <el-tab-pane label="托盘出库查询" name="deliveryStorage"
            ><div class="formCenter">
              <el-form
                :model="queryParams"
                size="large"
                :inline="true"
                ref="queryForm"
                :rules="formRules"
                label-width="90px"
              >
                <el-form-item label="巷道:" prop="startRegion">
                  <el-input
                    v-model="queryParams.startRegion"
                    placeholder="请输入巷道"
                    clearable
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item label="任务类型" prop="workType">
                  <el-select
                    v-model="queryParams.workType"
                    placeholder="请选择任务类型"
                    clearable
                  >
                    <el-option
                      v-for="dict in dict.type.work_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="托盘编码:" prop="containerNo">
                  <el-input
                    v-model="queryParams.containerNo"
                    placeholder="请输入托盘编码"
                    clearable
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="medium"
                    @click="handleQuery"
                    >搜索</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
            <el-table
              :data="tableData"
              border
              height="680"
              v-loading="loading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
            >
              <el-table-column align="center" prop="startRegion" label="巷道">
              </el-table-column>
              <el-table-column align="center" prop="workType" label="任务类型">
              </el-table-column>
              <el-table-column
                align="center"
                prop="upperSystemTaskId"
                label="WMS任务号"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="allocationDetailsId"
                label="分配单ID"
              >
              </el-table-column>
              <el-table-column align="center" prop="containerNo" label="托盘码">
              </el-table-column>
              <el-table-column align="center" prop="extend1" label="商品名称">
              </el-table-column>
              <el-table-column align="center" prop="lotId" label="批次号">
              </el-table-column>
              <el-table-column align="center" prop="planQty" label="商品数量">
              </el-table-column>
              <el-table-column
                align="center"
                prop="createTime"
                label="任务接收时间"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="priority"
                label="任务优先级"
              >
              </el-table-column>
              <el-table-column align="center" prop="status" label="任务状态">
              </el-table-column>
              <el-table-column
                align="center"
                prop="taskIndex"
                label="搬运任务序号"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="fromArea"
                label="搬运任务起始区域"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="toArea"
                label="搬运任务目标区域"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="sendTime"
                label="搬运任务发送时间"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="moveTime"
                label="搬运任务开始执行时间"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="arriveTime"
                label="搬运任务到达时间"
              >
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="托盘入库查询" name="putInStorage"
            ><div class="formCenter">
              <el-form
                :model="InqueryParams"
                size="large"
                :inline="true"
                ref="InqueryForm"
                :rules="InformRules"
                label-width="90px"
              >
                <el-form-item label="巷道:" prop="startRegion">
                  <el-input
                    v-model="InqueryParams.startRegion"
                    placeholder="请输入巷道"
                    clearable
                    @keyup.enter.native="InhandleQuery"
                  />
                </el-form-item>
                <el-form-item label="托盘编码:" prop="containerNo">
                  <el-input
                    v-model="InqueryParams.containerNo"
                    placeholder="请输入托盘编码"
                    clearable
                    @keyup.enter.native="InhandleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="medium"
                    @click="InhandleQuery"
                    >搜索</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
            <el-table
              :data="IntableData"
              border
              height="680"
              v-loading="Inloading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
            >
              <el-table-column align="center" prop="endRegion" label="巷道">
              </el-table-column>
              <el-table-column align="center" prop="taskType" label="任务类型">
              </el-table-column>
              <el-table-column
                align="center"
                prop="upperSystemTaskId"
                label="WMS任务号"
              >
              </el-table-column>
              <el-table-column align="center" prop="containerNo" label="托盘码">
              </el-table-column>
              <el-table-column align="center" prop="udf01" label="商品名称">
              </el-table-column>
              <el-table-column align="center" prop="lotId" label="批次号">
              </el-table-column>
              <el-table-column align="center" prop="qty" label="商品数量">
              </el-table-column>
              <el-table-column
                align="center"
                prop="createTime"
                label="任务接收时间"
              >
              </el-table-column>
              <el-table-column align="center" prop="status" label="任务状态">
              </el-table-column>
              <el-table-column
                align="center"
                prop="taskIndex"
                label="搬运任务序号"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="fromArea"
                label="搬运任务起始区域"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="toArea"
                label="搬运任务目标区域"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="sendTime"
                label="搬运任务发送时间"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="moveTime"
                label="搬运任务开始执行时间"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="arriveTime"
                label="搬运任务到达时间"
              >
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="立库阈值设置" name="databaseThreshold">
            <div class="formCenter">
              <el-form
                :model="thresholdqueryParams"
                size="large"
                :inline="true"
                ref="thresholdqueryForm"
                :rules="thresholdformRules"
                label-width="95px"
              >
                <el-form-item label="区域编号:" prop="areaNo">
                  <el-select
                    v-model="thresholdqueryParams.areaNo"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in thresholdOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="medium"
                    @click="thresholdhandleQuery"
                    >搜索</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
            <el-table
              :data="thresholdtableData"
              border
              height="680"
              v-loading="thresholdloading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
            >
              <el-table-column align="center" prop="areaNo" label="区域编号">
              </el-table-column>
              <el-table-column
                align="center"
                prop="maxCount"
                label="最大容器数"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.maxCount"
                    placeholder="请输入最大容器数"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                align="center"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="handleMNcontainers(scope.row)"
                    >修改最大容器数</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="agv待执行任务查询" name="agvTask"></el-tab-pane>
        </el-tabs>
      </div>
    </div>
    <VueBarcodeScanner :result="barCode" />
    <div class="footer">
      <el-dialog
        title="操作验证"
        :visible.sync="centerDialogVisible"
        width="22%"
        left
        :close-on-click-modal="false"
      >
        <el-form
          :model="passForm"
          status-icon
          :rules="passrules"
          ref="passForm"
          label-width="60px"
          class="demo-ruleForm"
        >
          <el-form-item label="密码" prop="pass">
            <el-input
              type="password"
              v-model="passForm.pass"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit('passForm')"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  getBarcode,
  getwcsList,
  getPickwcsList,
  getInpickwcsList,
  getwaitwcsList,
} from "@/api/subSystem/continer";
import {
  getPriority,
  getthresholdAreaNo,
  getUpdateMaxCount,
} from "@/api/multiPass";
import { getcheckPassword } from "@/api/subSystem/continer";
import VueBarcodeScanner from "vue-barcode-scanner";
export default {
  dicts: ["work_type", "bill_type", "status_type"],
  components: {
    VueBarcodeScanner,
  },
  data() {
    var passwordError = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
      } else {
        getcheckPassword(value).then((res) => {
          this.priorityNum = res.msg;
          if (res.msg == "admin") {
            callback();
          } else if (res.msg == "supper") {
            callback();
          } else if (res.msg == "false") {
            callback(new Error("密码错误"));
          }
        });
      }
    };
    return {
      // 优先级数值
      priorityNum: null,
      centerDialogVisible: false,
      passForm: {
        pass: null,
      },
      passrules: {
        pass: [{ validator: passwordError, trigger: "blur" }],
      },
      // 标签页
      activeName: "barCodename",
      // 当前页
      currentTabName: "barCodename",
      // 总条数
      // total: 0,
      loading: false,
      // 托盘出库
      bCloading: false,
      queryParams: {
        startRegion: null,
        containerNo: null,
        workType: null,
      },
      formRules: {
        containerNo: [
          { required: true, message: "请输入托盘编号", trigger: "blur" },
        ],
      },
      // 托盘入库
      Inloading: false,
      InqueryParams: {
        startRegion: null,
        containerNo: null,
      },
      InformRules: {
        containerNo: [
          { required: true, message: "请输入托盘编号", trigger: "blur" },
        ],
      },
      barCode: null,
      tableData: [],
      bCtableData: [],
      IntableData: [],
      // 托盘待执行任务查询
      // WMS任务组
      taskid: null,
      // 订单类型
      tasktype: null,
      // 托盘码
      palletid: null,
      // 优先级
      taskgrade: null,
      priortyOptions: [
        {
          value: "A",
          label: "A",
        },
        {
          value: "B",
          label: "B",
        },
      ],
      pTtotal: 0,
      pTtableData: [],
      pTloading: false,
      pTqueryParams: {
        pageNum: 1,
        pageSize: 10,
        billType: null,
        billNo: null,
        status: null,
        containerNo: null,
        upperSystemTaskId: null,
      },
      pTformRules: {
        containerNo: [
          { required: false, message: "请输入托盘编号", trigger: "blur" },
        ],
      },
      // 阀值
      // 区域编号
      thresholdOptions: [
        {
          value: "JXB40101",
          label: "JXB40101",
        },
        {
          value: "JXB40102",
          label: "JXB40102",
        },
        {
          value: "JXB40201",
          label: "JXB40201",
        },
        {
          value: "JXB40202",
          label: "JXB40202",
        },
        {
          value: "CK201",
          label: "CK201",
        },
        {
          value: "CK401",
          label: "CK401",
        },
        {
          value: "CK402",
          label: "CK402",
        },
        {
          value: "CK501",
          label: "CK501",
        },
      ],
      thresholdareaNo: null,
      thresholdmaxCount: null,
      thresholdtableData: [],
      thresholdloading: false,
      thresholdqueryParams: {
        // pageNum: 1,
        // pageSize: 10,
        areaNo: null,
      },
      thresholdformRules: {
        areaNo: [
          { required: false, message: "请输入区域编号", trigger: "blur" },
        ],
      },
      // 全局变量修改巷道
      thresholdvalue: 0,
    };
  },
  created() {
    // this.getlistdata();
    // this.getReportdata();
    // this.timer = setInterval(() => {
    //   this.getlistdata();
    //   this.getReportdata();
    // },10000);
  },
  mounted() {
    this.$refs.barcodeInput.focus();
    this.pThandleQuery();
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },

  methods: {
    // 标签页切换
    handleClick(tab, event) {
      this.currentTabName = tab.name;
      // console.log(this.currentTabName);
      if(this.currentTabName=="agvTask"){
        this.$router.push("/agvExecuted");
      }
    },
    //立库阀值查询
    thresholdhandleQuery() {
      getthresholdAreaNo(this.thresholdqueryParams).then((res) => {
        console.log(res);
        this.thresholdtableData = [res.data];
      });
    },
    //修改最大容器数
    handleMNcontainers(row) {
      this.thresholdareaNo = row.areaNo;
      this.thresholdmaxCount = parseInt(row.maxCount, 10);
      // console.log(111,this.thresholdareaNo,this.thresholdmaxCount);
      this.centerDialogVisible = true;
      this.passForm.pass = null;
      this.thresholdvalue = 2;
    },
    // 托盘出库
    handleQuery() {
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          getPickwcsList(this.queryParams).then((res) => {
            this.tableData = res.data;
            this.loading = false;
          });
        }
      });
    },
    // 托盘入库
    InhandleQuery() {
      this.$refs.InqueryForm.validate((valid) => {
        if (valid) {
          this.Inloading = true;
          getInpickwcsList(this.InqueryParams).then((res) => {
            this.IntableData = res.data;
            this.Inloading = false;
          });
        }
      });
    },
    // 托盘待执行任务查询
    pThandleQuery() {
      this.$refs.pTqueryForm.validate((valid) => {
        if (valid) {
          this.pTloading = true;
          getwaitwcsList(this.pTqueryParams).then((res) => {
            this.pTtableData = res.rows;
            this.pTtotal = res.total;
            this.pTloading = false;
          });
        }
      });
    },
    // 密码验证
    handleUpdate(row) {
      console.log("priorty", row.priorty);
      // WMS任务组
      this.taskid = row.upperSystemTaskId;
      //订单类型
      if (row.billType == "整件任务") {
        this.tasktype = "38";
      } else if (row.billType == "整托任务") {
        this.tasktype = "39";
      } else if (row.billType == "盘点任务") {
        this.tasktype = "40";
      }
      // 托盘码
      this.palletid = row.containerNo;
      // 优先级
      this.taskgrade = row.priorty;
      this.centerDialogVisible = true;
      this.passForm.pass = null;
      this.thresholdvalue = 1;
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.thresholdvalue == 1) {
            // console.log(111);
            if (this.priorityNum == "admin") {
              if (this.taskgrade >= 10) {
                const randomMsgld = Math.floor(
                  Math.random() * 1000000
                ).toString();
                getPriority({
                  msgId: randomMsgld,
                  taskId: this.taskid,
                  taskType: this.tasktype,
                  taskGrade: this.taskgrade,
                  palletId: this.palletid,
                  Udf01: "",
                  Udf02: "",
                  Udf03: "",
                }).then((res) => {
                  console.log(res);
                  this.pThandleQuery();
                  this.activeName = this.currentTabName;
                  this.$modal.msgError(res.data[0].msg);
                });
                this.centerDialogVisible = false;
              } else {
                this.$modal.msgError("普通用户可修改的优先级值必须大于等于10");
              }
            }
            if (this.priorityNum == "supper") {
              const randomMsgld = Math.floor(
                Math.random() * 1000000
              ).toString();
              getPriority({
                msgId: randomMsgld,
                taskId: this.taskid,
                taskType: this.tasktype,
                taskGrade: this.taskgrade,
                palletId: this.palletid,
                Udf01: "",
                Udf02: "",
                Udf03: "",
              }).then((res) => {
                console.log(res);
                this.pThandleQuery();
                this.activeName = this.currentTabName;
                this.$modal.msgError(res.data[0].msg);
              });
              this.centerDialogVisible = false;
            }
          }
          if (this.thresholdvalue == 2) {
            // console.log(222);
            getUpdateMaxCount({
              areaNo: this.thresholdareaNo,
              maxCount: this.thresholdmaxCount,
            }).then((res) => {
              console.log(res);
              this.thresholdhandleQuery();
              this.activeName = this.currentTabName;
            });
            this.centerDialogVisible = false;
          }
        }
      });
    },
    bChandleQuery() {
      if (this.barCode) {
        this.bCloading = true;
        getwcsList(this.barCode).then((res) => {
          this.bCtableData = res.data;
          this.bCloading = false;
        });
      } else {
        this.$modal.msgError("请输入任务编号");
      }
    },
    goBack() {
      this.$router.push("/subSystem1");
    },
  },
};
</script>

<style lang="scss" src='@/assets/styles/multiCrossing.scss' scoped>
</style>
